package com.javasm.mingming.common.exception;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author javasm
 * @version 0.1
 * @className JavasmExceptionAdvice
 * @descriptioin:
 * @date 2024/12/30 14:41
 * @since jdk11
 */
@RestControllerAdvice
public class JavasmExceptionAdvice {

    Logger logger = LogManager.getLogger(JavasmExceptionAdvice.class);
    //处理自定义异常
    @ExceptionHandler(JavasmException.class)
    public ResponseEntity<JavasmExceptionEnum> f1(JavasmException e){
        JavasmExceptionEnum exceptionEnum = e.getExceptionEnum();
        return ResponseEntity.status(HttpStatus.OK).body(exceptionEnum);
    }
    //这样写也可以
    public JavasmExceptionEnum f2(JavasmException e){
        return e.getExceptionEnum();
    }
   /* @ExceptionHandler(Exception.class)
    public ResponseEntity<R> f3(Exception e){
        logger.error(e);
        R r = new R();
        r.setCode(500);
        r.setMsg(e.getMessage());
        return ResponseEntity.ok(r);
    }*/
}
